clear all
clear matrix
set more off, perm

**************************************************
***********Program dofile*************************
**************************************************


***Creating programs***

capture program drop dupprogram 
program define dupprogram
	duplicates tag LopNr, gen(d)
	drop if d>0
	drop d
end


capture program drop YearsEducation
program define YearsEducation													/*According to convention at IFAU*/
	gen double yearseducation = .
	replace yearseducation = 6.6  if Sun2000niva_old == "*"
	replace yearseducation = 7.5  if Sun2000niva_old == "1"
	replace yearseducation = 9.4  if Sun2000niva_old == "2"
	replace yearseducation = 11.2 if Sun2000niva_old == "3"
	replace yearseducation = 12.4 if Sun2000niva_old == "4"
	replace yearseducation = 14.2 if Sun2000niva_old == "5"
	replace yearseducation = 17   if Sun2000niva_old == "6"
	replace yearseducation = 20.4 if Sun2000niva_old == "7"
end

capture program drop differentnamesFirst
program define differentnamesFirst 

	/*Membership organization*/			
	gen memberparti = .
	replace memberparti = 0 if MA0040 == 2
	replace memberparti = 1 if MA0040 == 1 

	gen memberboende = .
	replace memberboende = 0 if MA0050 == 2
	replace memberboende = 1 if MA0050 == 1 

	gen memberimmig = .
	replace memberimmig = 0 if MA0060 == 2
	replace memberimmig = 1 if MA0060 == 1 

	gen memberpension = .
	replace memberpension = 0 if MA0070 == 2 
	replace memberpension = 1 if MA0070 == 1 

	gen memberparent = .
	replace memberparent = 0 if MA0080 == 2 
	replace memberparent = 1 if MA0080 == 1 

	gen membersport = . 
	replace membersport = 0 if (MA0600 == 2 | MA0603 == 2)
	replace membersport = 1 if (MA0600 == 1 | MA0603 == 1)  

	gen memberenviron = .
	replace memberenviron = 0 if MA0606 == 2  
	replace memberenviron = 1 if MA0606 == 1 

	gen memberhandi = .
	replace memberhandi = 0 if MA0624 == 2 
	replace memberhandi = 1 if MA0624 == 1 

	gen memberwoman = .
	replace memberwoman = 0 if MA0630 == 2 
	replace memberwoman = 1 if MA0630 == 1 

	*Active*
	gen activeparti = .
	replace activeparti = 0 if MA0044 == 2
	replace activeparti = 1 if MA0044 == 1 

	gen activeboende = .
	replace activeboende = 0 if MA0054 == 2
	replace activeboende = 1 if MA0054 == 1 

	gen activeimmig = .
	replace activeimmig = 0 if MA0064 == 2
	replace activeimmig = 1 if MA0064 == 1 

	gen activepension = .
	replace activepension = 0 if MA0074 == 2 
	replace activepension = 1 if MA0074 == 1 

	gen activeparent = .
	replace activeparent = 0 if MA0084 == 2 
	replace activeparent = 1 if MA0084 == 1 

	gen activesport = . 
	replace activesport = 0 if (MA0601 == 2 | MA0604 == 2)
	replace activesport = 1 if (MA0601 == 1 | MA0604 == 1)  

	gen activeenviron = .
	replace activeenviron = 0 if MA0607 == 2  
	replace activeenviron = 1 if MA0607 == 1 

	gen activehandi = .
	replace activehandi = 0 if MA0625 == 2 
	replace activehandi = 1 if MA0625 == 1 

	gen activewoman = .
	replace activewoman = 0 if MA0631 == 2 
	replace activewoman = 1 if MA0631 == 1 
end




**********************
capture program drop differentnamesSecond
program define differentnamesSecond 

	/*Membership organization*/			
	gen memberparti = .
	replace memberparti = 0 if MA0040 == 2			
	replace memberparti = 1 if MA0040 == 1  

	gen memberboende = 0
	replace memberboende = 1 if MA0910 > "0" & MA0910 != "NA" 

	gen memberimmig = 0
	replace memberimmig = 1 if MA0913 == "0" & MA0913 != "NA" 

	gen memberpension = 0
	replace memberpension = 1 if MA0915 == "0" & MA0915 != "NA" 

	gen memberparent = 0
	replace memberparent = 1 if MA0911 == "0" & MA0911 != "NA" 

	gen membersport = 0 
	replace membersport = 1 if (MA0903 > "0" | MA0904 > "0" | MA0905 > "0") & (MA0903 != "NA" | MA0904 != "NA" | MA0905 != "NA")  

	gen memberenviron = 0
	replace memberenviron = 1 if MA0906 > "0" & MA0906 != "NA"

	gen memberhandi = 0
	replace memberhandi = 1 if MA0912 > "0" & MA0912 != "NA" 

	gen memberwoman = 0
	replace memberwoman = 1 if MA0914 > "0" & MA0914 != "NA"  

	*Active*
	gen activeparti = .
	replace activeparti = 0 if MA0044 == "2"
	replace activeparti = 1 if MA0044 == "1" 

	gen activeboende = .
	replace activeboende = 0 if MA0054 == "2"
	replace activeboende = 1 if MA0054 == "1" 

	gen activeimmig = .
	replace activeimmig = 0 if MA0064 == "2"
	replace activeimmig = 1 if MA0064 == "1" 

	gen activepension = .
	replace activepension = 0 if MA0074 == "2" 
	replace activepension = 1 if MA0074 == "1" 

	gen activeparent = .
	replace activeparent = 0 if MA0084 == "2" 
	replace activeparent = 1 if MA0084 == "1" 

	gen activesport = . 
	replace activesport = 0 if (MA0683 == "2" | MA0604 == "2" | MA0688 == "2")
	replace activesport = 1 if (MA0683 == "1" | MA0604 == "1" | MA0688 == "2")  

	gen activeenviron = .
	replace activeenviron = 0 if MA0607 == "2"  
	replace activeenviron = 1 if MA0607 == "1" 

	gen activehandi = .
	replace activehandi = 0 if MA0625 == "2" 
	replace activehandi = 1 if MA0625 == "1" 

	gen activewoman = .
	replace activewoman = 0 if MA0631 == "2" 
	replace activewoman = 1 if MA0631 == "1" 
end



